package com.itda.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import java.io.IOException;

/**
 * @Author: itda
 * @Date: 2024/4/29 21:58
 * @Description: DemoFilter
 */
//@WebFilter(urlPatterns = "/*")//JavaWeb三大组件之一 在Springboot中要想使用JavaWeb的三大组件必须要在启动类上加上@@ServletComponentScan
public class DemoFilter implements Filter {
    @Override//初始化方法,只调用一次
    public void init(FilterConfig filterConfig) throws ServletException {
        System.out.println("init 初始化方法执行了");
    }

    @Override//拦截到请求之后调用,调用多次
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        System.out.println("Demo拦截到了请求...放行前逻辑");
        //放行到下一个过滤器,没有就放行访问web资源
        filterChain.doFilter(servletRequest,servletResponse);

        System.out.println("Demo拦截到了请求...放行后逻辑");
    }

    @Override//销毁方法,只调用一次
    public void destroy() {
        System.out.println("destroy 销毁方法执行了");
    }
}
